<template>
	<div class="sys-dictType-container">
		<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" width="700px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto">
				<el-form-item label="设备类型" prop="deviceType"
					:rules="{ required: true, message: '设备类不为空', trigger: 'change' }">
					<el-select v-model="state.ruleForm.deviceType" placeholder="请选择设备类型">
						<!-- 假设这里有几个枚举值，根据实际情况修改 -->
						<el-option label="AGV" :value="0"></el-option>
						<el-option label="提升机" :value="1"></el-option>
						<!-- <el-option label="类型3" value="2"></el-option> -->
					</el-select>
				</el-form-item>
				<el-form-item label="设备ID" prop="deviceId"
					:rules="{ required: true, message: '设备ID不为空', trigger: 'change' }">
					<el-input v-model="state.ruleForm.deviceId"></el-input>
				</el-form-item>
				<el-form-item label="设备状态" prop="deviceStatus"
					:rules="{ required: true, message: '设备状态不为空', trigger: 'change' }">
					<el-select v-model="state.ruleForm.deviceStatus" placeholder="请选择设备状态">
						<!-- 假设这里有几个枚举值，根据实际情况修改 -->
						<el-option label="可用" :value="0"></el-option>
						<el-option label="故障" :value="1"></el-option>
						<el-option label="维修中" :value="2"></el-option>
						
					</el-select>
				</el-form-item>

				<!-- 设备位置 -->
				<el-form-item label="设备楼层" prop="storey"
					:rules="{ required: true, message: '设备楼层不为空', trigger: 'change' }">
					<el-input v-model="state.ruleForm.storey"></el-input>
				</el-form-item>
				<el-form-item :label="$slots['提升机_label'] || '提升机出/入口'" prop="inOrOut">
					<template #提升机_label>
						<span style="color: red;">提审计</span>出/入口
					</template>
					<el-select v-model="state.ruleForm.inOrOut" placeholder="请选择提升机出入口">
						<!-- 假设这里有几个枚举值，根据实际情况修改 -->
						<el-option label="入口" :value="0"></el-option>
						<el-option label="出口" :value="1"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="描述" prop="description" 
				:rules="{ required: true, message: '描述不为空', trigger: 'change' }">
				<el-input v-model="state.ruleForm.description"  clearable type="textarea" ></el-input>
			</el-form-item>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel" >取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>
			
		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="Edidevice">


import { getAPI } from '/@/utils/axios-utils';
import { AccountTypeEnum, UpdateDictTypeInput } from '/@/api-services/models';
import { useUserInfo } from '/@/stores/userInfo';
import { ref, onMounted, reactive } from 'vue';

import { InseertDeviceApi, UpdateDeviceApi } from '/@/api-services/apis/warehosue-device-api'; // 导入 API 服务
import { DeviceMaintenance, DeleteDeviceMaintenance } from '/@/api-services/models/warehous-devicemaintenance -input'; // 导入获取实体
import { Message } from '@element-plus/icons-vue/dist/types';
import { update } from 'lodash-es';
import { clone } from 'sortablejs';

// 打开弹窗
const openDialog = (row: any) => {
	state.ruleForm = JSON.parse(JSON.stringify(row));
	state.isShowDialog = true;
	console.log(state.ruleForm);
	ruleFormRef.value?.resetFields();

};


const props = defineProps({
	title: String,
});
const emits = defineEmits(['handleQuery']);
const ruleFormRef = ref();
const state = reactive({
	loading: false,
	isShowDialog: false,
	ruleForm: {} as DeviceMaintenance,


});
// 在 onMounted 生命周期钩子中获取仓库数据

// 关闭弹窗
const closeDialog = () => {
	emits('handleQuery');
	state.isShowDialog = false;
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean) => {
		if (!valid) return;
		//state.ruleForm.id != undefined && state.ruleForm.id > 0
		if (props.title && props.title.includes("编辑")) {

			console.log(state.ruleForm);
			await UpdateDeviceApi(state.ruleForm);

		} else {

			await InseertDeviceApi(state.ruleForm);
		}
		closeDialog();
	});
};

// 导出对象
defineExpose({ openDialog });
</script>
